/**
 * JAVACC DEMO 1.0
 * @copy right zbxsoft company All rights reserved. 
 * @Package com.zbxsoft.platform.template.helper  
 */
package com.apache.info.template.helper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.apache.api.vo.ParamsVo;
import com.apache.info.entity.PubMetadata;
import com.apache.info.entity.PubSortInfo;
import com.apache.info.manager.PubMetadataManager;
import com.apache.info.manager.PubSortInfoManager;
import com.apache.info.template.FreemarkerHelper;
import com.apache.info.util.FileOperate;

/**
 * description:  生成属性实现类
 * @author dyhou 创建时间：2016-9-30  
 * @Copyright(c)2014:北京中百信软件技术有限公司
 */
public class EntityTempManager extends SupperTemplateManager {

	public EntityTempManager(PubSortInfoManager sortInfoManager, PubMetadataManager metadataManager) {
		this.init(sortInfoManager, metadataManager);
	}

	public boolean createEntity(Map<String, Object> param) {
		boolean mark = false;
		List<PubSortInfo> list = (List<PubSortInfo>) param.get("sortList");
		String jarPath = String.valueOf(param.get("packPath"));
		String prefix = String.valueOf(param.get("projectName")) + "/src/main/";
		String xmlPath = String.valueOf(param.get("filePath")) + "/" + prefix + "java/" + jarPath.replace(".", "/")
				+ "/entity/";
		FileOperate.getInstance().newCreateFolder(xmlPath);
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("packPath", jarPath);
		try {
			ParamsVo vo = new ParamsVo();
			PubMetadata metadata = new PubMetadata();
			for (PubSortInfo map : list) {
				data.put("sort", map);
				metadata.setSortId(String.valueOf(map.getSortId()));
				vo.setObj(metadata);
				List mts = (List) metadataManager.getList(vo);
				data.put("metadatas", mts);
				String result = FreemarkerHelper.instance().getTemplateStr("entity/ObjName.inc", data);
				FileOperate.getInstance().newCreateFile(xmlPath + String.valueOf(map.getObjName()) + ".java", result);
			}
			mark = true;
		} catch (Exception e) {
			log.error("生成实体失败", e);
		}
		return mark;
	}
}
